import { createApp } from "vue";
import App from "./App.vue";
import { createPinia } from "pinia";
import router from "./router";
import i18n from "@/locales/i18n.ts";
import "@/styles/reset.less";
import "vant/lib/index.css";
import "@/styles/resetVant.less";
import "@/styles/theme.less";
import "@/styles/basicStyles.less";
import piniaPluginPersisted from "pinia-plugin-persistedstate";
import "amfe-flexible";
import enUS from "vant/lib/locale/lang/en-US";
import { Locale, Lazyload } from "vant";
import { InstallGuideConfigInterval } from "@/constant";
// import { HomeAxios } from "@/api";
// import { FiltrationFun } from "@/utils";
import VConsole from "vconsole";
// 初始化 VConsole
const vconsole = new VConsole();
console.log("初始化", vconsole);
const setRem = () => {
  const baseSize = 52.5; // 对应 750px 设计稿
  const maxWidth = 525; // 设计稿的最大宽度
  const width = document.documentElement.clientWidth || window.innerWidth;
  const scale = width <= maxWidth ? width / maxWidth : 1;
  document.documentElement.style.fontSize = baseSize * scale + "px";
};
setRem();
// 当窗口大小发生变化时，重新计算
window.addEventListener("resize", setRem);
Locale.use("en-US", enUS);
const app = createApp(App);
const pinia = createPinia();
window.addEventListener("beforeinstallprompt", event => {
  console.log("beforeinstallpromptMian.js", event);
  event.preventDefault();
  InstallGuideConfigInterval.deferredPrompt = event;
  console.log("有获取到吗", InstallGuideConfigInterval.deferredPrompt);
});

// if ("serviceWorker" in navigator) {
//   window.addEventListener("load", () => {
//     navigator.serviceWorker
//       .register("/dev-dist/registerSW.js")
//       .then(registration => {
//         console.log("Service Worker registered with scope:", registration.scope);
//         registration.pushManager.getSubscription().then(function (subscription) {
//           if (subscription) {
//             console.log("main这的pwa订阅", JSON.stringify(subscription));

//             HomeAxios.getUserPwaServerKeys().then(res => {
//               //console.log("获取推送公钥id", res.serverKey);
//               const getServerKey = FiltrationFun.urlB64ToUint8Array(res.serverKey);
//               // console.log("是什么", JSON.stringify(getServerKey));
//               HomeAxios.addUserPwaSub({ subscription: JSON.stringify(getServerKey) }).then(res => {
//                 console.log("订阅成功", res);
//               });
//             });
//           } else {
//             console.log("没有订阅");
//             FiltrationFun.subscribeUser(registration);
//           }
//         });
//       })
//       .catch(error => {
//         console.error("Service Worker registration failed:", error);
//       });
//   });
// }
import "animate.css";
app.use(pinia);
app.use(router);
app.use(i18n);
app.use(Lazyload, {
  lazyComponent: true,
});
pinia.use(piniaPluginPersisted);
app.mount("#app");
